<template>
  <div style="background-color: #FFFFFF; padding: 20px;">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="环境名称" prop="env_title">
        <el-input v-model="ruleForm.env_title"></el-input>
      </el-form-item>

      <el-form-item label="请求协议" prop="env_protocol">
        <el-input v-model="ruleForm.env_protocol"></el-input>
      </el-form-item>

      <el-form-item label="IP地址" prop="env_ip">
        <el-input v-model="ruleForm.env_ip"></el-input>
      </el-form-item>

      <el-form-item label="端口" prop="env_port">
        <el-input v-model="ruleForm.env_port"></el-input>
      </el-form-item>

      <el-form-item label="域名" prop="env_domain">
        <el-input v-model="ruleForm.env_domain"></el-input>
      </el-form-item>

      <el-form-item label="TOKEN" prop="token">
        <el-input v-model="ruleForm.token"></el-input>
      </el-form-item>

      <el-form-item label="localStorage" prop="local_storage">
        <el-input type="textarea" :autosize="{ minRows: 5, maxRows: 15}" placeholder="请输入内容"
                  v-model="ruleForm.local_storage"></el-input>
      </el-form-item>

      <el-form-item label="sessionStorage" prop="session_storage">
        <el-input type="textarea" :autosize="{ minRows: 5, maxRows: 15}" placeholder="请输入内容"
                  v-model="ruleForm.session_storage"></el-input>
      </el-form-item>

      <el-form-item label="状态" prop="status">
        <el-select v-model="ruleForm.status" placeholder="请选择状态" style="width: 100%;">
          <el-option
            v-for="(item,index) in optionsCommon"
            :key="index"
            :label="item.value"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm()">保存</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>

</template>
<script>
  export default {
    name: 'Addenvironment',
    data() {
      return {

        optionsCommon: [],  // 存储CommonChoices实际数据的列表

        EditUrl: this.$http.environmentURL,  // get编辑的URL
        EditIdStr: 'environment_id',  // 模块id字符串
        pushObjName: 'environment',  // 成功后跳转的路由

        ruleForm: {
          env_title: '',//环境名称
          env_protocol: '',//请求协议
          env_ip: '', //IP地址
          env_port: '',//端口
          env_domain: '', //域名
          token:'',  // 环境token
          local_storage:'',  // 本地存储
          session_storage:'',  // 会话存储
          status: '',//状态
        },  //
        rules: {
          env_title: [
            {required: true, message: '请输入环境名称', trigger: 'blur'}
          ],
          env_protocol: [
            {required: true, message: '请输入请求协议', trigger: 'blur'},
            {min: 0, max: 20, message: '长度在 0 到 100 个字符', trigger: 'blur'}
          ],
          env_ip: [
            {required: true, message: '请输入IP地址', trigger: 'change'}
          ],
          env_port: [
            {required: true, message: '请输入端口', trigger: 'blur'},
            {min: 0, max: 20, message: '长度在 0 到 6 个字符', trigger: 'blur'}
          ],
          env_domain: [
            {required: false, message: '请输入域名', trigger: 'blur'},
            {min: 0, max: 200, message: '长度在 0 到 200 个字符', trigger: 'blur'}
          ],
          token: [
            {required: false, message: '请输入token', trigger: 'blur'},
            {min: 0, max: 200, message: '长度在 0 到 200 个字符', trigger: 'blur'}
          ],
          status: [
            {required: true, message: '请选择状态', trigger: 'change'}
          ],
        }
      };
    },
    created() {
      this.getEditData();   // get回将要编辑的数据
      this.optionsCommon = this.getChoices.common
    },
    methods: {
      submitForm() {
        this.$myTool.submitForm(this)
      },

      // get回将要编辑的数据
      getEditData() {
        this.$myTool.getEditData(this)
      },

      //
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    },
    computed: {
      getChoices() {
        return this.$store.state.choicesInfo
      }
    },
  }
</script>
